package com.home.zqt.platform.configure;

import com.alibaba.fastjson.JSONObject;
import org.beetl.ext.simulate.JsonUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * @author soon
 * @description: TODO
 * @date 2019-06-28 14:14
 **/
@Component
public class StringToListConverter<T> implements Converter<String, List<T>> {

    @Override
    public List<T> convert(String source) {
        Type type  =  (Class < T > ) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        Class clazz = type.getClass();
        List<T> list = JSONObject.parseArray(source, clazz);
        return  list;
    }
}
